﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebClient
{
    public partial class Products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack) {
                loadData(1);
            }
        }

        private void loadData(int ipage) {
            WebDataContext db = new WebDataContext();
            int flag = -1;
            String sfind = "";
            try {
                String sId = Request.Params["id"];
                if(sId != null)
                    flag = Convert.ToInt32(sId);
                sfind = Request.Params["find"];
                if (sfind == null)
                    sfind = "";
            }
            catch { 
            }
            if (flag == -1)
                sfind = "";

            List<DTO.Products> list = db.product.findProducts(sfind,flag);
            Button bt;
            int page = list.Count / 9;
            panelPages.Controls.Clear();
            //for (int i = 1; i < page; i++) {
            //    bt = new Button();
            //    bt.Text = i.ToString();
            //    bt.ID = i.ToString();
            //    bt.Click +=new EventHandler(bt_Click);
            //    panelPages.Controls.Add(bt);
            //    Literal li = new Literal();
            //    li.ID = "li" + i.ToString("00");
            //    li.Text = "|";
            //    if(i<page -1)
            //        panelPages.Controls.Add(li);
            //}
            this.grdPoduct.DataSource = list;
            this.grdPoduct.DataBind();
        }

        protected void bt_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;
            int p = Convert.ToInt32(bt.ID);
            loadData(p);
        }
    }
}